package org.airlink.persistence.criteria
{
	import flash.utils.Dictionary;
	
	import flex.persistence.EntityManager;
	import flex.persistence.criteria.Expression;
	import flex.persistence.criteria.Predicate;
	
	import mx.collections.ArrayList;
	
	import org.airlink.persistence.EntityIntrospector;
	
	public class PredicateImpl extends ExpressionImpl implements Predicate		
	{


		private var _booleanOperator:String;
		private var _exps:Array;
		private var _negated:Boolean;
		
		
		
		
		public function PredicateImpl(booleanOperator:String = null, restrictions:Array = null){
			if(booleanOperator != null){
				if(booleanOperator != "AND" && booleanOperator != "OR")
					this._booleanOperator = "AND";
				else this._booleanOperator = booleanOperator;
			} else
				this._booleanOperator = "AND";
			
			if(restrictions != null)
				_negated = false;
			
			_exps = new Array();
			for each (var item:Predicate in restrictions)
			add(item);
		}
		
		public function add(s:Expression):PredicateImpl {
			_exps.push(s);
			return this;
		}
		

		
		public function get operator():String{
			return _booleanOperator;
		}
		
		public function isNegated():Boolean {
			return _negated;
		}

		
		public function get expressions():Array {
			if(_exps == null)
				return null;			
			var result:Array = new Array();			
			for each (var item:Expression in _exps)
			result.push(item);			
			return result;			
		}
		
		public function not():Predicate {
			//	return new Expressions.Not(this).markNegated();
			return null; 
		}		
		
	}
}